package com.haiyou.dc.thread.test3;

public class TestVolatile {
    //volatile保证多线程数据的同步，避免指令重排
    private volatile static int num = 0;

    public static void main(String[] args) {
        new Thread(() -> {
            System.out.println("------>" + num);
            while (num == 0) {

            }
            System.out.println("xxxxxxxxx->" + num);
        }).start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num = 1;
    }
}
